<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8" %>
<script type="text/javascript" charset="UTF-8">
	$(function() {
		$('#paramGrid').datagrid({
			url : ctx+'/sys/param/list.htm',
			toolbar : '#paramToolbar',
			title : '参数配置',
			iconCls : 'icon-save',
			pagination : true,
			pageSize : 10,
			pageList : [ 10, 20],
			fit : true,
			fitColumns : true,
			nowrap : false,
			border : false,
			idField : 'id',
			frozenColumns : [ [ {
				field : 'id',
				title : 'id',
				width : 50,
				checkbox : true
			}, {
				field : 'tag',
				title : '标签',
				width : 100,
				sortable : true
			}, {
				field : 't_name',
				title : '表名',
				width : 100,
				sortable : true
			}] ],
			columns : [ [ {
				field : 'code',
				title : '参数值',
				width : 100
			},{
				field : 'code_desc',
				title : '参数描述',
				width : 100
				 
			}, {
				field : 'order_by',
				title : '序号',
				width : 150,
				sortable : true
			}, {
				field : 'remark',
				title : '备注',
				width : 150
			}  ] ],
			onDblClickCell: function(index,field,value){
				var rows = $('#paramGrid').datagrid('getRows');
				openParamDialog(rows[index].id);
			}
		});

	});
	function openParamDialog(id) {
		var title="参数新增";
		var href=ctx+'/jsp/sys/param.jsp?id='+id;
		if(id.length>0){
			title="参数修改";
		}
		$('<div/>').dialog({
			href : href ,
			width : 520,
			height : 300,
			modal : true,
			title : title,
			buttons : [{
				text : '保存',
				handler : function() {
					var d = $(this).closest('.window-body');
					var data=JSON.stringify($('#paramForm').form("serialize"));
					$("#paramForm input[name=data]").val(data);
					$('#paramForm').form('submit', {
						url : ctx+'/sys/param/save.htm',
						success : function(result){
							result = JSON.parse(result);
							$.messager.show({
								msg : result.r?"操作成功":"操作失败",
								title : "提示"
							});
							$('#paramGrid').datagrid('reload').datagrid('unselectAll');
							d.dialog('destroy');
						}
					});
				}
			},
			{
				text : '取消',
				handler : function(){
					$(this).closest('.window-body').dialog('destroy');
				}
			}],
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
	}
	function paramAppend() {
		openParamDialog("");
	}

	function paramEdit() {
		var rows = $('#paramGrid').datagrid('getSelections');
		if (rows.length != 1 && rows.length != 0) {
			var names = [];
			for ( var i = 0; i < rows.length; i++) {
				names.push(rows[i].name);
			}
			$.messager.show({
				msg : '只能择一个记录编辑！您已经选择了【' + names.join(',') + '】' + rows.length + '条',
				title : '提示'
			});
		} else if (rows.length == 1) {
			openParamDialog(rows[0].id);
		}else{
			$.messager.show({
				msg : '请选择一条记录进行操作',
				title : '提示'
			});
		}
	}
	
	function paramRemove() {
		var ids = [];
		var rows = $('#paramGrid').datagrid('getSelections');
		if (rows.length > 0) {
			$.messager.confirm('请确认', '您要删除当前所选项目？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].id);
					}
					$.ajax({
						url : ctx+'/sys/param/del.htm',
						data : {
							id : ids.join(',')
						},
						cache : false,
						success : function(response) {
							$('#paramGrid').datagrid('unselectAll');
							$('#paramGrid').datagrid('reload');
							$.messager.show({
								title : '提示',
								msg : '删除成功！'
							});
						}
					});
				}
			});
		} else {
			$.messager.alert('提示', '请选择要删除的记录！', 'error');
		}
	}

	function searchFun() {
		$('#paramGrid').datagrid('load', {
			tableName : $('#paramToolbar select[comboname=tableName]').combobox('getValue'),
			tag : $('#paramToolbar select[comboname=tag]').combobox('getValue')
		});
	}
	function clearFun() {
		$('#paramToolbar input').val('');
		$('#paramGrid').datagrid('load', {});
	}
</script>
<div id="paramToolbar" class="datagrid-toolbar" style="height: auto;">
	<fieldset>
		<legend>筛选</legend>
		<table class="tableForm">
			<tr>
				<th>表名：</th>
				<td >
					<select name="tableName"  style="width: 150px;" class="easyui-combobox"  
                  			 data-options="editable:false,
                  			 			   valueField:'t_name',
                  			 			   textField:'t_name',
                  			 			   url:ctx+'/sys/paramGroup/getParam.htm?info=2',
                  			 			   onSelect: function(rec){   
								           var url = ctx+'/sys/paramGroup/getParam.htm?info=9VG9kpkVLO&info=' + rec.t_name; 
								            $('#paramToolbar select[comboname=tag]').combobox('setValues','');  
								           $('#paramToolbar select[comboname=tag]').combobox('reload', url);   
								        }">
           				</select>
				</td>
				<th>标签名：</th>
				<td >
					<select name="tag"  style="width: 150px;" class="easyui-combobox"  
						data-options="valueField:'tag',textField:'tag'" 
						></select>
				</td>
				<td><a class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="searchFun();" href="javascript:void(0);">查找</a>
					<a class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="clearFun();" href="javascript:void(0);">清空</a>
				</td>
			</tr>
		 
		</table>
	</fieldset>
	<div>
		<a class="easyui-linkbutton" iconCls="icon-add" onclick="paramAppend();" plain="true" href="javascript:void(0);">增加</a>
		<a class="easyui-linkbutton" iconCls="icon-remove" onclick="paramRemove();" plain="true" href="javascript:void(0);">删除</a> 
		<a class="easyui-linkbutton" iconCls="icon-edit" onclick="paramEdit();" plain="true" href="javascript:void(0);">编辑</a>
		<a class="easyui-linkbutton" iconCls="icon-undo" onclick="$('#paramGrid').datagrid('unselectAll');" plain="true" href="javascript:void(0);">取消选中</a>
	</div>
</div>
<table id="paramGrid"></table>
 
 
 